home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / slib / tk / demos / square < prev    next >
Text File  |  1994-09-20  |  1KB  |  51 lines

  1. #!///////////////////////////////////////////////////////////////////////////usr/STAGE/bin/wish -f
  2. #
  3. # This script generates a demo application containing only
  4. # a "square" widget.  It's only usable if Tk has been compiled
  5. # with tkSquare.c and with the -DSQUARE_DEMO compiler switch.
  6. # This demo arranges the following bindings for the widget:
  7. # Button-1 press/drag:        moves square to mouse
  8. # "a":                toggle size animation on/off
  9.  
  10. square .s
  11. pack .s -expand yes -fill both
  12. wm minsize . 1 1
  13.  
  14. bind .s <1> {center %x %y}
  15. bind .s <B1-Motion> {center %x %y}
  16. bind .s a animate
  17. focus .s
  18.  
  19. # The procedure below centers the square on a given position.
  20.  
  21. proc center {x y} {
  22.     set a [.s size]
  23.     .s position [expr $x-($a/2)] [expr $y-($a/2)]
  24. }
  25.  
  26. # The procedures below provide a simple form of animation where
  27. # the box changes size in a pulsing pattern: larger, smaller, larger,
  28. # and so on.
  29.  
  30. set inc 0
  31. proc animate {} {
  32.     global inc
  33.     if {$inc == 0} {
  34.     set inc 3
  35.     timer
  36.     } else {
  37.     set inc 0
  38.     }
  39. }
  40.  
  41. proc timer {} {
  42.     global inc
  43.     set s [.s size]
  44.     if {$inc == 0} return
  45.     if {$s >= 40} {set inc -3}
  46.     if {$s <= 10} {set inc 3}
  47.     .s size [expr {$s+$inc}]
  48.     after 30 timer
  49. }
  50.